<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加权限</title>
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/global.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/table.css" />
    <style>
        .del{vertical-align:bottom;margin-left:5px;}
    </style>
</head>

<body>
<div class="admin-main">
    <blockquote class="layui-elem-quote">
        当前产品:<span style="color:red;"><{$product.name}></span>
    </blockquote>

    <div style="margin: 15px;">
        <form class="layui-form" method="post" action="/admin/product/bannerUpdate">
            <div class="layui-form-item">
                <div id="images">
                    <{volist name="banner" id="item"}>
                    <div class="layui-input-block">
                        <img src="<{$item.image}>" style="width:200px;height:200px;" />
                        <br /><br />
                        <input type="text" name="desc[]" value="<{$item.desc}>" required lay-verify="required" placeholder="请输入描述" autocomplete="off" class="layui-input">
                        <br />
                        <input type="text" name="image_alt[]" value="<{php}>if(!empty($item['image_alt'])){echo $item['image_alt'];}<{/php}>"  placeholder="请输入图片描述" class="layui-input" />
                        <br />
                        <input type="hidden" value="<{$item.image}>" name="images[]" />
                        <span class="layui-btn layui-btn-danger del" >删除</span>
                    </div>
                    <{/volist}>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">产品图片</label>
                <div class="layui-input-block">
                    <div style="margin-top: 10px;"><input type="file" name="file" class="layui-upload-file"></div>
                </div>
            </div>

            <input type="hidden" value="<{$product.id}>" name="id" />


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button lay-filter="add" lay-submit class="layui-btn">提交</button><a href="/admin/product/index" class="layui-btn layui-btn-danger">返回上级</a>
                </div>
            </div>
        </form>
    </div>

</div>
<script type="text/javascript" src="/static/lib/layuiadmin/plugins/layui/layui.js"></script>



<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form();
    });
    layui.use(["layer","upload"],function(){
        var $ = layui.jquery;

        layui.upload({
            url: '/admin/upload/upload'
            ,success: function(res){
                console.log(res); //上传成功返回值，必须为json格式
                if(1 == res.code){
                    $("#images").append('<div class="layui-input-block"> \
                    <img src="'+res.data.src+'" style="width:200px;height:200px;" /> \
                    <br /><br /> \
                    <input type="text" name="desc[]" required lay-verify="required" placeholder="请输入描述" autocomplete="off" class="layui-input"> \
                    <br /> \
                    <input type="hidden" value="'+res.data.src+'" name="images[]" /> \
                    <span class="layui-btn layui-btn-danger del" >删除</span> \
                    </div>');

                }else{
                    layer.msg(res.msg);
                }
            }
        });

        $("#images").delegate(".del",'click',function(){
            $(this).parent().remove();
        });
    });

</script>

</body>

</html>